﻿<!-- Views/Admin/Exams.cshtml -->
@model List<WebApplication1.Models.Exam>

@{
    ViewBag.Title = WebApplication1.Utilities.LanguageManager.GetText("ExamManagement");
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white">
                    <div class="d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">
                            @WebApplication1.Utilities.LanguageManager.GetText("ExamManagement")
                        </h5>
                        <a href="@Url.Action("CreateExam", "Admin")" class="btn btn-light btn-sm">
                            @WebApplication1.Utilities.LanguageManager.GetText("CreateExam")
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    @if (TempData["SuccessMessage"] != null)
                    {
                        <div class="alert alert-success alert-dismissible fade show" role="alert">
                            @TempData["SuccessMessage"]
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                    }

                    @if (Model.Count == 0)
                    {
                        <div class="alert alert-info text-center">
                            @WebApplication1.Utilities.LanguageManager.GetText("NoExamData")
                        </div>
                    }
                    else
                    {
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead class="table-dark">
                                    <tr>
                                        <th width="5%">ID</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("ExamName")</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("Description")</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("PassScore")</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("Duration")</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("CreateDate")</th>
                                        <th>@WebApplication1.Utilities.LanguageManager.GetText("Status")</th>
                                        <th width="25%">@WebApplication1.Utilities.LanguageManager.GetText("Action")</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var exam in Model)
                                    {
                                        <tr>
                                            <td>@exam.ExamId</td>
                                            <td>@exam.ExamName</td>
                                            <td>@(string.IsNullOrEmpty(exam.Description) ? WebApplication1.Utilities.LanguageManager.GetText("NoDescription") : exam.Description)</td>
                                            <td><span class="badge bg-info">@exam.PassScore @WebApplication1.Utilities.LanguageManager.GetText("Score")</span></td>
                                            <td>@exam.Duration @WebApplication1.Utilities.LanguageManager.GetText("Minutes")</td>
                                            <td>@exam.CreatedDate.ToString("yyyy-MM-dd")</td>
                                            <td>
                                                @if (exam.IsActive)
                                                {
                                                    <span class="badge bg-success">@WebApplication1.Utilities.LanguageManager.GetText("Active")</span>
                                                }
                                                else
                                                {
                                                    <span class="badge bg-secondary">@WebApplication1.Utilities.LanguageManager.GetText("Inactive")</span>
                                                }
                                            </td>
                                            <td>
                                                <div class="btn-group btn-group-sm" role="group">
                                                    <a href="@Url.Action("EditExam", "Admin", new { id = exam.ExamId })"
                                                       class="btn btn-warning btn-sm" title="@WebApplication1.Utilities.LanguageManager.GetText("Edit")">
                                                        @WebApplication1.Utilities.LanguageManager.GetText("Edit")
                                                    </a>
                                                    <a href="@Url.Action("Questions", "Admin", new { examId = exam.ExamId })"
                                                       class="btn btn-primary btn-sm" title="@WebApplication1.Utilities.LanguageManager.GetText("ManageQuestions")">
                                                        @WebApplication1.Utilities.LanguageManager.GetText("Questions")
                                                    </a>
                                                    <a href="@Url.Action("DeleteExam", "Admin", new { id = exam.ExamId })"
                                                       class="btn btn-danger btn-sm" title="@WebApplication1.Utilities.LanguageManager.GetText("Delete")">
                                                        @WebApplication1.Utilities.LanguageManager.GetText("Delete")
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 确保引用必要的脚本 -->
<script src="~/Scripts/jquery-3.6.0.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>

<script>
    $(document).ready(function () {
        // 关闭警告框
        $('.alert .btn-close').click(function () {
            $(this).parent('.alert').fadeOut();
        });

        // 自动隐藏成功消息
        setTimeout(function () {
            $('.alert-success').fadeOut();
        }, 5000);
    });
</script>